#!/usr/bin/python3
import os,sys
from inspect import getmembers

def class_list(t,m=None):
	m=m or sys.modules[__name__]
	for name,obj in getmembers(m,inspect.isclass):
		if issubclass(obj,t) and obj is not t:yield obj

def dir_name(a=None):
	if not a:a=os.getcwd()
	return a[a.rfind(os.path.sep)+1:]

def list_files(d,k=False):
	for fn in os.listdir(d):
		if fn[-1]=='~':continue
		if k:yield (os.path.join(d,fn),fn[:fn.rfind('.')])
		else:yield os.path.join(d,fn)

def load_dict(d,cb,*ar,open_mode='r',**kw):
	return dict([(k,cb(open(fn,open_mode),*ar,**kw)) for fn,k in list_files(d,True)])
